home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Tools / Languages / MacMETH 3.2.1 / MEdit ƒ / Macros ƒ / Macros.MCR < prev   
Encoding:
Text File  |  1994-03-21  |  29.6 KB  |  990 lines  |  [TEXT/MEDT]

  1. **********************************************************************************
  2. * This macro file is useful for Modula-2 programming. It allows you to
  3. * insert all important program-structures with one key.
  4. * derived from Pascal.Mcr of   Matthias Aebi  31.03.86
  5. * written           : 16.10.86   Alex Itten
  6. * Last modification : 20.10.86   Alex Itten
  7. *                      18.08.87   Andreas Fischlin
  8. *                      31.08.87   Andreas Fischlin to MEdit V1.54 adapted
  9. *                      11.02.88   A. Fischlin, Wrap and rearrange comment
  10. *                                 macro (22,36) added
  11. *                      11.09.88   Olivier Roth, adapted to pers. use
  12. *                      24.10.88   Olivier Roth, some bug fixes
  13. *                      30.01.89   Andreas Fischlin, adapted to pers. use
  14. *                                 and update to 1989 version made
  15. *                      13.02.89   Andreas Fischlin some minor changes in
  16. *                                 macro procedure (without VAR), and
  17. *                                 small format fixes in macro 5, 35, 44
  18. *                                 MacPlus version separated from Mac IIx
  19. *                                 version and making a generic version
  20. *                                 (see list of markers below)
  21. *                      14.02.89   Correction for Mac Plus
  22. *                      27.02.89   Thomas Nemecek, adapted to pers. use
  23. *                      10.06.89   Olivier Roth, menu layout & some short
  24. *                                 cuts (cmd-W is Close, Wrap->A).
  25. *                      23.08.89   A. Fischlin adapted to new versions of
  26. *                                 MacMETH, DM, and ModelWorks
  27. *                                 Case now Option^S instead of Option^A
  28. *                                 so that wrap in both versions may use
  29. *                                 Command^A resp. Option^A
  30. *                      25.10.89   O.R. removal of CONST, TYPE, VAR.
  31. *                                 Goto M2-Error added.
  32. *                      25.10.89   A.F. all versions corrected, new import
  33. *                                 list for ModelWorks 1.3 inserted
  34. *                      30.04.90   A.F. all versions corrected for DM 2.0,
  35. *                                 MacMETH 2.6+ and ModelWorks 2.0
  36. *                      15.09.90   A.F. versions corrected for DM 2.01 and
  37. *                                 ModelWorks 2.01
  38. *                      20.09.90   O.R.: version for MacMETH error support,
  39. *                                 complete revision.
  40. *                      01.10.90   O.R.: version 1.6 (with new MComp version)
  41. *                      26.10.90   O.R.: version 1.62 (with new MComp & MEdit)
  42. *                      09.11.90   O.R.: version 1.64 (with new MComp & MEdit)
  43. *                      24.11.90   O.R.: version 1.65 for students & ETH faculty
  44. *                      11.01.91   O.R.: version 1.66 for students & ETH faculty
  45. *                     12.06.91   A.F.: version 1.70 using no longer absolute
  46. *                                path to MacMETH but now relative path to
  47. *                                RAMSES shell
  48. *                      24.06.91     A.F.: Bug fix in macro «Find M2-Error» where
  49. *                                 WName result was returned inconsistently. Now
  50. *                                 using $1 as intermediate storage variable.
  51. *                      01.07.91   O.R.: version 1.71 for students & ETH faculty
  52. *                      12.07.91   O.R.: version 1.72 for students & ETH faculty
  53. *                      13.08.91   O.R.: version 1.73 for students & ETH faculty
  54. *                      20.11.91   A.F.: Minor version corrections and updates
  55. *                                 for RAMSES shell 1.02b4, MacMETH 3.0, DM 2.031,
  56. *                                 and ModelWorks 2.031.
  57. *                      13.01.92   D.G.: Updates for RAMSES Shell 1.2, 
  58. *                                 MacMETH 3.0, DM 2.2 and ModelWorks 2.2.
  59. *                      10/03/92   D.G.: Updates for RAMSES Shell 1.2b0, MacMETH 3.2 
  60. *                      31/08/92     A.F.: Version 1.79 
  61. *                     29/09/92   jth final release for MacMETH 3.2.
  62. *                      02/10/92     - J. Thoeny as user of this generic version added
  63. *                                Reconstruction of a generic version from
  64. *                                - J. Thoeny's new XX version
  65. *                                - Avoiding any non ASCII characters to allow
  66. *                                for easier port of code to MS-DOS PC and Unix 
  67. *                                machines
  68. *                      22/10/92     A.F.: Support for MiniRAMSESShell added, i.e.
  69. *                                mini* markers added
  70. *                     24/10/92   Launch shell sends now a comp message ('DMEv',231,0,0)
  71. *                      08/11/92     For RAMSES Mini shell support Cmd^0 must not
  72. *                                 send a 'MnCh' high level event.
  73. *                      13/11/92     Support for new MEdit version 1.8
  74. *                     02/12/92   Added Launch Shell and Simulate Macro
  75. *                      05/12/92     A.F.: Adapted for RAMSES 2.0
  76. *                     29/04/93   jth support for warning 263
  77. *                      07/06/93     A.F.: Adapted for RAMSES 2.2
  78. *
  79. **********************************************************************************
  80. * Versions:
  81. *    M2-Generic(1.80).MCR
  82. *    MComp 1.40
  83. *    MEdit 1.80
  84. **********************************************************************************
  85. * Legend:
  86. *  Δ            - Shift
  87. *  xNum         - key x on numeric key pad
  88. *  Opt          - Option (alt) key
  89. *  ^            - between two keys means press simultaneously
  90. *  CursLeft     - Cursor Left
  91. *  CursRight    - Cursor Right
  92. *  CursUp       - Cursor Up
  93. *  CursDown     - Cursor Down
  94. *
  95. *  Version markers: This file is a generic macro version.  The beginning 
  96. *                    of the lines are marked with a particular comment string
  97. *                    see list below.  To produce a particular version of these
  98. *                    macros simply remove all markers of the particular kind
  99. *                    to make the particular lines active.  Otherwise the macro
  100. *                    compiler will treat them as a comment only.  Warning: Be
  101. *                    careful not to destroy this generic version while making
  102. *                    a particular version (Use menu command Save as... and NOT
  103. *                    Save!).
  104. *  List of used markers (first '*' is omitted to allow for global remove, so
  105. *                         that the list below is not destroyed while producing
  106. *                         a particular version)
  107. *    af*        - Line used in A. Fischlin's version for any Mac
  108. *    jt*        - Line used in J. Thoeny's version for any Mac
  109. *    or*        - Line used in O. Roth's version for any Mac SE & II sg
  110. *    tn*        - Line used in T. Nemecek's version for any Mac II sg
  111. *    XX*        - Line used in version for: student, staff & faculty of ETHZ
  112. *    mini*      - Line used in version for Mini RAMSES Shell
  113. *  legend: sg = swiss german keyboard, us = us ascii keyboard
  114. **********************************************************************************
  115.  
  116. *
  117. * Globally used string resources ('STR '):
  118. * ID 0-4
  119. *
  120. * Globally used string variables:
  121. *
  122. * $9 : path to folder containing "ErrList.DOK" (relative to MacMETH folder)
  123. * $8 : name of the M2-shell
  124. * $7 : last name of user
  125. * $6 : first name of user
  126. * $5 : pattern expression for finding M2-error mark
  127. * $4 : 
  128. * Locally used:
  129. * $3 : div.
  130. * $2 : procedure name
  131. * $1 : div.
  132. * $0 : module name
  133.  
  134. *
  135. * Locally used numeric variables:
  136. * #0, #1, #2, #6-#9
  137. * --------------------------------------------------------------------------------
  138.  
  139.  
  140.  
  141. * 01
  142. * Find all compiled M2 files and open the erroneous/first in list
  143. * NOTE: this is the autoexec macro!
  144. !"Open work file[s]/0" • {
  145. *   at least one window must be open for autoexec macro
  146. *    New;  IF Window(1)  { Window(0);  Close };
  147.     Set( $7, GetStr(0) );
  148.     IF Len($7) = 0 {
  149. * adapt here for your configuration:
  150. * *********************************
  151. *jt*        Set($8," MacMETH 3.2.1");        Set($9,":M2Tools 3.2.1:");      Set($7,"Thoeny");                 Set($6,"Juerg");
  152. *or*        Set($8," MacMETH 3.2.1");        Set($9,":M2Tools 3.2.1:");      Set($7,"Roth");                   Set($6,"Olivier");
  153. *af*        Set($8," RMSMacMETH 3.2.1");    Set($9,":M2Tools 3.2.1:");      Set($7,"Fischlin");               Set($6,"Andreas");
  154. *tn*        Set($8," MacMETH 3.2.1");        Set($9,":M2Tools 3.2.1:");      Set($7,"Nemecek");                Set($6,"Thomas");
  155.         Set($8," MacMETH 3.2.1");        Set($9,":M2Tools 3.2.1:");      Set($7,"(*.Your last name.*)"); Set($6,"(*.Your first name.*)");
  156. * *********************************
  157.         Call(09);  }
  158.     ELSE  {
  159.         Set( $6, GetStr(1) );
  160.         Set( $8, GetStr(2) );
  161.         Set( $9, GetStr(3) );
  162.     };
  163.     Set($5,"†[ 0-9][ 0-9][0-9]†");
  164.     IF NOT Open( "err.DAT")  {
  165.       Alert( Concat( "Can't find and open the Modula-2 compilation error file: '", "err.DAT", "'" ) );
  166.       Alert( "Move MEdit and/or compile your Modula-2 source file(s)" );  }
  167.     ELSE  {
  168.       Set(#0,0);
  169.       Select(0,0);
  170.       Set(#1,AbsPos);
  171.       WHILE Find("¿")  {
  172.         Set(#2, AbsPos-#1 );  Set(#2, #2 MOD 7 );
  173.         IF #2 = 0  {
  174. *          i.e. filename mark found
  175. *         NOTE: ".*[]" contains 0C in brackets!
  176.           EFind(".*[]");
  177.           Select(L.,C.|L.,C:-1);
  178.           Set($1,$S);
  179.           Select(L.,C:+1|L.,C:+2);
  180.           Set(#1,AbsPos);        
  181.           IF StrCmp($S,"¡",1) = 0  {
  182.             IF NOT Open($1)  {
  183.               Alert( Concat("Can't find and open source file '", $1, "' containing Modula-2 errors!") );
  184.               Alert( "Try Macro 'Configure' and/or compile your Modula-2 source file(s)" );
  185.               SelAbs(AbsPos+1);  }
  186.             ELSE  {
  187.               Set(#0,#0+1);
  188.               Window(#0);
  189.             };
  190.           };
  191.           SelAbs(AbsPos-1);
  192.         };
  193.       };
  194.       IF #0 = 0 {
  195. *       no file with compilation errors, open first:
  196.         Select(0,1);
  197.         EFind(".*[]");
  198.         Select(L.,C.|L.,C:-1);
  199.         Set($1,$S);
  200.         IF NOT Open($1)  {
  201.           Alert( Concat("Can't find and open Modula-2 file '", $1, "'") );
  202.           Alert( "Try Macro 'Configure' and/or compile your Modula-2 source file(s)" );  }
  203.         ELSE  {
  204.           Set(#0,#0+1);
  205.           Window(#0);
  206.         };
  207.       };
  208.       Close;
  209.       IF #0 > 0  Call(02);
  210.     };
  211. };
  212.  
  213. * 02
  214. * jumps ,to the next Modula-2 error mark and displays an alert
  215. "Find next error/E" {
  216.     IF Len($S) > 5 Select(L.,C:-5|L.,C:);
  217.     IF EFind ($5) {
  218.       Select(L.,C.|L.,C:)!;
  219.       Set($3,SubStr($S,2,3));
  220.       Set(#8,Val($3));
  221.       IF #8 = 263 {
  222.           Select(L.,C<|L.,C:);
  223.           Select(L.,C.-1|L.,C:);
  224.           Select(L.,C<|L.,C:);
  225.           Select(L.,C>|L.,C:);
  226.           Select(L.,C.-1|L.,C:);
  227.         Set(#7,Ord(SubStr($S,1,1)));
  228.         IF #7 = Ord("=")  {
  229.               Select(L.,C.-1|L.,C:);
  230.             Select(L.,C<|L.,C:);
  231.         } ELSE {
  232.             IF NOT #7 = Ord(",") AND NOT #7 = Ord(" ") {
  233.                 Select(L.,C.+1|L.,C:);
  234.             };
  235.         };
  236.           IF Len($S) < 5{
  237.               Select(L.,C:-5|L.,C:);
  238.               Select(L.,C<|L.,C:);
  239.           };
  240.           Beep;
  241.       };
  242.       Set(#7,0);  Set(#8,0);  Set(#9,0);
  243.       WHILE #8 = 0 AND #7 = 0  {
  244.         IF Window(#9)  {
  245.           IF StrCmp(WName,"ErrList.DOK",0) = 0  Set(#8,1);
  246.         }
  247.         ELSE
  248.           Set(#7,1);
  249.         Set(#9,#9+1);
  250.       };
  251.       IF #8 = 0  {
  252.         IF Open( Concat($9,"ErrList.DOK") )  {
  253.           PlaceW( ScrH-50, 2, ScrH-2, 500 );
  254.           Set(#8,1);
  255.         }
  256.         ELSE
  257.           Alert( Concat("Can't find and open compilation error message file '",$9,"ErrList.DOK'"));
  258.       };
  259.       IF #8 = 1  {
  260.         Select(VAL($3)-40,0);
  261.         Set( $1, Concat( "^- ", $3, " .*" ) );
  262.         EFind( $1 )!;
  263.         IF NOT Val($3) = 263 {
  264.             EAlert( "Modula-2 Error:", SubStr($S,8,255) );
  265.         };
  266.         Window(#7);
  267.       };
  268.     }
  269.     ELSE  {
  270.         Beep;
  271.         Select(L.,C.|L:,C:)!;
  272.     }
  273. };
  274.  
  275.  
  276.  
  277. * 03
  278. * Clear error marks, close and Launch Modula-2 shell
  279. "Clear, save & launch/1" {
  280.     Call(07);
  281. * Compile/simulate message 'COMP'  ≈  17231 = C + O = 43H = 4FH;  19792 = M + P = 4DH + 50H 
  282.     IF POSTHL("RAMS","DMEv",17231, 19792, 0) ELSE IF POSTHL("ETHM","DMEv",17231, 19792, 0);
  283. *    IF POSTHL("RAMS","MnCh",129,5,0) ELSE IF POSTHL("ETHM","MnCh",129,5,0);
  284.     Launch( GetStr(2) );
  285. };
  286.  
  287. * --------------------------------------------------------------------------------
  288. * 04
  289. * insert a line in the menu
  290. "-" {};
  291.  
  292. * 05
  293. * Launch Modula-2 shell and Simulate
  294. "Launch shell & simulate/2" •{
  295. * Compile/simulate message 'COMP'  ≈  17231 = C + O = 43H = 4FH;  19792 = M + P = 4DH + 50H 
  296.     IF POSTHL("RAMS","DMEv",17231, 19792, 0) ELSE IF POSTHL("ETHM","DMEv",17231, 19792, 0);
  297.     Launch( GetStr(2) );
  298. };
  299.  
  300.  
  301. * 06
  302. * Launch Modula-2 shell
  303. "Launch shell/3" •{
  304.     Launch( GetStr(2) );
  305. };
  306.  
  307.  
  308. * 07
  309. * Close Modula-2-source file
  310. "Clear error marks & save/8" {
  311.     Select(0,0);
  312.     WHILE EFind ($5)   Clear;
  313.     Save;
  314.     Select(0,0);
  315.     Close;
  316. };
  317.  
  318. * 08
  319. * Remove Modula-2-error marks
  320. * alternate (invisible) errmark: EFIND("")
  321. "Clear error marks/9" {
  322.     Sect(0);
  323.     Select(0,0);
  324.     WHILE EFind ($5)   Clear;
  325. };
  326.  
  327.  
  328.  
  329. * 09
  330. "Configure" •{
  331.     Set( $4, GetStr(0) );
  332.     IF NOT Len($4) = 0  Set($7,$4);
  333.     IF Prompt( "Your last name:", $7 )  {
  334.         IF NOT Len($4) = 0  Set( $6, GetStr(1) );
  335.         IF Prompt( "Your first name:", $6 )  {
  336.             IF NOT Len($4) = 0  Set( $9, GetStr(3) );
  337.             IF Prompt( "Relative path to 'ErrList.DOK':", $9 )  {
  338.                 IF NOT Len($4) = 0  Set( $8, GetStr(2) );
  339.                 IF Prompt( "Name of the Modula-2 (MacMETH) shell:", $8 )  {
  340.                     PutStr( 0, $7 );
  341.                     PutStr( 1, $6 );
  342.                     PutStr( 2, $8 );
  343.                     PutStr( 3, $9 );
  344.                 }
  345.             }
  346.         }
  347.     }
  348. };
  349.  
  350.  
  351. * --------------------------------------------------------------------------------
  352. * 10
  353. * insert a line in the menu
  354. "-" {};
  355.  
  356. * 11
  357. * Insert a DEFINITION MODULE template (Option^M)
  358. "MODULE DEF          Opt M" 346 •{
  359.   IF Prompt("Enter DEF Module name ",$0) {
  360.     New;
  361.     Push;
  362.     Insert("DEFINITION MODULE ");
  363.     Insert($0);
  364.     Insert(";\N");
  365.     Insert("\N");
  366.     Insert("  (*******************************************************************\N");
  367.     Insert("\N");
  368.     Insert("    Module  ");  Insert($0);  Insert("     (Version 1.0)\N");
  369.     Insert("\N");
  370.     Insert(Concat("              Copyright (c) 1993 by ",$6," ",$7," and Swiss\N"));
  371.     Insert("              Federal Institute of Technology Zürich ETHZ\N");
  372.     Insert("\N");
  373.     Insert("      Purpose (*.  purpose  .*)\N");
  374.     Insert("              \N");
  375.     Insert("      Remarks (*.  remarks.  .*)\N");
  376.     Insert("              \N");
  377.     Insert("      Programming\N");
  378.     Insert("\N");
  379. *af*    Insert("          o Design and Implementation\N");
  380. *jt*    Insert("          o Design\N");
  381. *or*    Insert("          o Design and Implementation\N");
  382. *tn*    Insert("          o Design\N");
  383.     Insert("          o Design\N");
  384.     Set($3,Concat("              ",SubStr($6,0,1),". ",$7,"         ",Date(2),"\N\N"));
  385.     Insert($3);
  386. *jt*    Insert("          o Implementation\N");  Insert($3);
  387. *tn*    Insert("          o Implementation\N");  Insert($3);
  388.     Insert("          o Implementation\N");  Insert($3);
  389.     Insert("              \N");
  390. *af*     Insert("          Systems Ecology\N");
  391. *jt*     Insert("          Systems Ecology\N");
  392. *or*     Insert("          Systems Ecology\N");
  393. *tn*     Insert("          Systems Ecology\N");
  394. *af*     Insert("          Institute of Terrestrial Ecology\N");
  395. *af*     Insert("          Department of Environmental Sciences\N");
  396. *jt*     Insert("          Department of Environmental Sciences\N");
  397. *or*     Insert("          Department of Environmental Sciences\N");
  398. *tn*     Insert("          Department of Environmental Sciences\N");
  399.     Insert("          Swiss Federal Institute of Technology Zurich ETHZ\N");
  400. *af*     Insert("          Grabenstr. 3\N");
  401. *jt*     Insert("          Grabenstr. 3\N");
  402. *or*     Insert("          Grabenstr. 3\N");
  403. *tn*     Insert("          Grabenstr. 3\N");
  404.     Insert("          CH-8952 Schlieren/Zurich\N");
  405.     Insert("          Switzerland\N");
  406.     Insert("\N");
  407.     Insert("          Last revision of definition:  ");
  408.     Insert(Concat(Date(2),"  ",SubStr($6,0,1),SubStr($7,0,1),"\N"));
  409.     Insert("\N");
  410.     Insert("  *******************************************************************)\N");
  411.     Insert("\N");
  412.     Insert("\N");
  413.     Insert("  (*.  .*)\N");
  414.     Insert("\N");
  415.     Insert("END ");
  416.     Insert($0);
  417.     Insert(".\N");
  418.     Call(38);
  419.     QSavAs(Concat($0,".DEF"));
  420.   };
  421. };
  422.  
  423.  
  424. * 12
  425. * Insert an IMPLEMENTATION MODULE template
  426. * [for DEF: Opt-M]
  427. "MODULE MOD/M" •{
  428.     IF Prompt("Enter Module name ",$0)  {
  429.       New;
  430.       Push;
  431.       Insert("(*. IMPLEMENTATION  .*)MODULE ");  Insert($0);  Insert(";\N\N");
  432.       Call(36);
  433.       Insert("\N");
  434.       Insert("\N");
  435.       Insert("BEGIN\N");
  436.       Insert("  (*.Statement.*)\N");
  437.       Insert("END ");
  438.       Insert($0);
  439.       Insert(".\N");
  440.       Call(38);
  441.       QSavAs(Concat($0,".MOD"));
  442.     };
  443. };
  444.  
  445.  
  446. * 13
  447. * Derive an empty implementation module from a correct definition module
  448. * NOTE: this version does NOT function CORRECTLY FOR:
  449. *       - syntactically incorrect DEF modules, e.g: unbalanced brackets, etc!
  450. *         ==> compile DEF module before running that macro
  451. *       - DEF modules containing more than 1 section (default = 32K)
  452. *         ==> remove some lengthy comments
  453. *       - if some keywords (i.e: PROCEDURE, END) appear in comments or types.
  454. *         ==> correct manually (anyway: the compiler will notice these errors).
  455. "Module DEF->MOD"  {
  456. * first copy all to a new window:
  457.     Select( 0,0 );
  458.     IF NOT Find( "DEFINITION" )  {
  459.       Alert( "Not as a definition module recognized!" ); }
  460.     ELSE  {
  461.       Select( 0,0 | L$,C$ );
  462.       Copy;
  463.       New;
  464.       Paste;
  465. * substitute DEFINITION by IMPLEMENTATION:
  466.       Select( 0,0 );
  467.       Push;
  468.       Find( "DEFINITION" );
  469.       Clear;
  470.       Insert( "IMPLEMENTATION" );
  471.       Find( " MODULE " );
  472.       Select( L.,C: );
  473.       EFind( "[A-Za-z][A-Za-z0-9]*" );
  474.       Set( $0, $S );
  475. * replace header comment (these string are written by macro "MODULE DEF"):
  476.       Select( L.+1,0 );
  477.       IF Find("(**************************************************")  {
  478.         Select( L.,0 );
  479.         Push;
  480.         Select( L.,C$-3 );
  481.         IF NOT Find("***************************************************)")
  482.           Find("*)");
  483.         Select(L[,C[ | L:,C:)!;
  484.         Drop;
  485.         Clear;
  486.       };
  487.       Call(36);
  488. * leave imports as they are:
  489.       WHILE Find ("IMPORT " )  {
  490.         Find( ";" );
  491.         IF C. = C$    Select( L.+1,0 )
  492.         ELSE          Select( L.  ,C.+1 );
  493.       };
  494. * clear heading const, type, var declarations:
  495. * note: const, type or var later inbetween procs are not filtered!
  496.       Push;
  497.       IF Find( "PROCEDURE " ) {
  498.         Select(L[,C[|L.-1,C$);
  499.         Clear;
  500.         Insert( "\N\N" );  };
  501.       Drop;
  502. * do procedures:
  503.       Select( L.,C.| L$,C$ );
  504.       Call(15);
  505. * make body:
  506.       Select( L$-10,0 );
  507.       WHILE Find( "END " )  {};
  508.       Select( L.,0 );
  509.       IF Find("END ")  {
  510.         Select( L.,0 );
  511.         Insert( "\N" );
  512.         Insert( "BEGIN\N ");
  513.         Insert( "  (*.Statement.*)\N" );  }
  514.       ELSE
  515.         Alert( "Bad syntax, no 'END' of module encountered!" );
  516.     };
  517.     Call(38);
  518.     QSavAs( Concat($0,".MOD") );
  519. };
  520.  
  521.  
  522.  
  523.  
  524. * 14
  525. * insert a PROCEDURE template (Option^P)
  526. "PROCEDURE           Opt P" 335 {
  527.   Push;
  528.   IF Prompt("Enter Procedure name",$2) {
  529.     Insert("PROCEDURE "); Insert($2);
  530. *af*    Insert(";(*. VAR .*)\n");
  531. *jt*    Insert(";(*. VAR .*)\n");
  532. *or*    Insert("( (*. VAR .*) );(*. .*)\n");
  533. *tn*    Insert(";(*. .*)\n");
  534.     Insert("( (*. VAR .*) );(*. .*)\n");
  535. *    Insert("  CONST  (*.Constants.*);\n");
  536. *    Insert("TYPE  (*.Types.*);\n");
  537. *    Insert("  VAR  (*.Variables.*);\n");
  538. *    Insert("\b\bBEGIN\n  (*.Statement.*)\n\b\bEND ");
  539.     Insert("BEGIN\n  (*.Statement.*)\n\b\bEND ");
  540.     Insert($2);
  541.     Insert(";(*. continue... .*)");    
  542.     Call(38);
  543.   };
  544. };
  545.  
  546.  
  547. * 15
  548. * expand the header of a "DEF" procedure to an empty implementation
  549. * assumes that the headers of procs to be expanded are selected before call
  550. * (supports recursive comments in argument list)
  551. * NOTE: that procedure will NOT function CORRECTLY if the brackets of
  552. *   comments or argument list are not balanced!
  553. "Proc[s] DEF->MOD"  {
  554.     Set( #1, L$ );
  555.     Select( L.,C. );
  556.     Push;
  557.     WHILE Find( "PROCEDURE " )  AND  L. < #1  {
  558.       Select( L.,C: );
  559.       EFind( "[A-Za-z][A-Za-z0-9]*" );
  560.       Set( $3, $S );
  561.       Set( #0, -1 );
  562.       IF EFind( "[;(]" )  {
  563.         IF Ord($S) = Ord(";")
  564.           Set( #0, 0 )
  565.         ELSE  {
  566.           Set( #0, 1 );
  567.           WHILE #0 > 0  {
  568.             IF EFind( "[()]" )  {
  569.               IF Ord($S) = Ord("(")  Set( #0, #0+1 )
  570.               ELSE  Set( #0, #0-1 );  }
  571.             ELSE
  572.               Set( #0, -1 );
  573.           };
  574.           IF #0 < 0  OR  NOT Find( ";" )  Set( #0, -1 );
  575.         };
  576.         IF #0 = 0  {
  577.           Select( L.+1, 0 );
  578.           Push;
  579.           Find( "(*" );
  580.           IF L. = L[  {
  581.             IF Find( "*)" )  {
  582.               Select( L[,C[ | L.,C: );
  583.               Clear;
  584.               Drop; }
  585.             ELSE
  586.               Pop;
  587.           }
  588.           ELSE
  589.             Pop;
  590.           Insert( "    (*. VAR .*)\N" );
  591.           Insert( "  BEGIN\N" );
  592.           Insert( "    (*.Statement.*)\N" );
  593.           Insert( "  END " );  Insert( $3 );  Insert( ";\N\N" );
  594. *         we have to add the number of inserted lines to update orig. selection
  595.           Set (#1, #1+5);  }
  596.         }
  597.       ELSE
  598.         Alert( "Bad syntax, no ';' found!" );
  599.     };
  600.     Call(38);
  601. };
  602.  
  603.  
  604.  
  605. * 16
  606. * insert a FOR-TO-DO template (Option^F)
  607. "FOR                       Opt F" 303 {
  608.     Push;
  609.     Insert("FOR (*.loop var.*):= (*.expr.*) TO (*.expr.*) DO\n");
  610.     Insert("  (*.Statement.*)\n");
  611.     Insert("\b\bEND(*FOR*);(*. continue... .*)");    
  612.     Call(38);
  613. };
  614.  
  615.  
  616. * 17
  617. * insert a CASE template (Option^S)
  618. "CASE                     Opt S" 301 {
  619.     Push;
  620.     Insert("CASE (*.expr.*) OF\n");
  621.     Insert("  (*.Constant.*)   : (*.Statement.*)\n");
  622.     Insert("\b\b| (*.Constant.*)   : (*.Statement.*)\n");
  623. *    Insert("\b\bELSE\N  (*.Statement.*);\n");
  624.     Insert("END(*CASE*);(*. continue... .*)");    
  625.     Call(38);
  626. };
  627.  
  628.  
  629. * 18
  630. * insert an IF-THEN-ELSE template (Option^I)
  631. * af version: Option^J is similar to Option^I
  632. * Using I may cause problems since I is diacritical with US-ASCII 
  633. * keyboard, i.e. the first character z typed will eventually carry 
  634. * a "^" if z may be used for a diacritical construction; otherwise
  635. * z will be preceeded by a "^".  In any case the user must first
  636. * delete these characters before he may (re)start with actual typing.
  637. * Remark: Option^J has nothing to do with macro Command J (Jump to line
  638. *         with a particular #)
  639. *af*"IF THEN                 Opt J" 338
  640. *jt*"IF THEN                 Opt J" 338
  641. *or*"IF THEN                 Opt I" 334
  642. *tn*"IF THEN                 Opt I" 334
  643. "IF THEN                 Opt J" 338
  644. {    Push;
  645.     Insert("IF (*.Condition.*) THEN\n  (*.Statement.*)\n");
  646.     Insert("\b\bELSE\n  (*.Statement.*)\n");
  647.     Insert("\b\bEND(*IF*);(*. continue... .*)");    
  648.     Call(38);
  649. };
  650.  
  651.  
  652. * 19
  653. *  Insert a WHILE-DO-END template (Option^W)
  654. "WHILE                   Opt W" 313 {
  655.     Push;
  656.     Insert("WHILE (*.Condition.*) DO\n");
  657.     Insert("  (*.Statement.*)\n");
  658.     Insert("\b\bEND(*WHILE*);(*. continue... .*)");    
  659.     Call(38);
  660. };
  661.  
  662.  
  663. * 20
  664. *  Insert a REPEAT-UNTIL template (Option^R)
  665. "REPEAT                  Opt R" 315 {
  666.     Push;
  667.     Insert("REPEAT\n");
  668.     Insert("  (*.Statement.*)\n");
  669.     Insert("\b\bUNTIL (*. Condition .*);(*. continue... .*)");    
  670.     Call(38);
  671. };
  672.  
  673.  
  674. * 21
  675. *  Insert a WITH-DO-END template (Option^H)
  676. "WITH                     Opt H" 304 {
  677.     Push;
  678.     Insert("WITH (*.Designator.*) DO\n");
  679.     Insert("  (*.Statement.*)\n");
  680.     Insert("\b\bEND(*WITH*);(*. continue... .*)");    
  681.     Call(38);
  682. };
  683.  
  684.  
  685. * --------------------------------------------------------------------------------
  686. * 22
  687. * insert a line in the menu
  688. "-" {};
  689.  
  690.  
  691.  
  692. * 23
  693. * puts comment-braces (like placeholders) around the current selection
  694. "Comment/K" {
  695.     Push;
  696.     Select(L],C]);
  697.     Insert(" .*)");
  698.     Select(L[,C[);
  699.     Insert("(*. ");
  700.     Pop;
  701.     IF L. = L:  Select(L.,C. | L:,C:+8)
  702.     ELSE        Select(L.,C. | L:,C:+5);
  703. };
  704.  
  705.  
  706. * 24
  707. * removes comment-braces at start and end of the current selection 
  708. * af version: (Option^K)
  709. *af*"Uncomment          Opt K" 340
  710. *jt*"Uncomment          Opt K" 340
  711. *or*"Uncomment/U" 340
  712. *tn*"Uncomment/U" 340
  713. "Uncomment          Opt K" 340 
  714. {
  715.     Push;
  716.     Select(L],C]-4 | L],C]);
  717.     Clear;
  718.     Select(L[,C[ | L[,C[+4);
  719.     Clear;
  720.     Pop;
  721. };
  722.  
  723.  
  724.  
  725.  
  726. * 25
  727. * Move all lines in the current selection to the right by inserting
  728. * a double space. do nothing for empty lines.
  729. "Move sel. right/R" {
  730.     Push;
  731.     WHILE L. < L] {
  732.         Select(L.,0);
  733.         IF NOT C$ = 0  Insert("  ");
  734.         Select(L.+1,0)!;
  735.     };
  736.     Select(L[,0|L],0);
  737.     Drop;
  738. };
  739.  
  740.  
  741. * 26
  742. * Move all lines in the current selection one position to the left
  743. * by deleting the leftmost characters. do nothing for empty lines.
  744. "Move sel. left/L" {
  745.     Push;
  746.     WHILE L. < L] {
  747.         Select(L.,0|L.,1);
  748.         Clear;
  749.         Select(L.+1,0)!;
  750.     };
  751.     Select(L[,0|L],0);
  752.     Drop;
  753. };
  754.  
  755.  
  756.  
  757. * 27
  758. * Replace all 'real' tabs by blank strings
  759. * this is useful to convert 'Edit'- to 'MEdit'-files
  760. "Replace tabs" {
  761.     SECT(0);
  762.     Select(0,0);
  763.     WHILE FIND("\9")   Insert("\t");
  764.     BEEP;
  765. };
  766.  
  767.  
  768. * 28
  769. * rearrange comments by wrapping the end of 
  770. * too long lines to the next line or filling lines too short lines
  771. * The comment must already contain comment braces such as "(*" and "*)"
  772. * and the Auto indent on resp. Line wrap around mode off!!!!!
  773. "Wrap comments/A" {
  774. * save current selection and assign last line of selection to #1
  775.     Push; Set(#1,L]);
  776. * set cursor to begin of selection and search for comment begin
  777.     Select(L[,C[); FIND("(*");
  778. * add at end of comment begin a new line in any case, update #1
  779.     Select(L.,C:); Insert("\n  "); Set(#1,#1+1);
  780. * save current selection, which is left margin of comment text
  781.     Push;
  782. * select and clear any blanks or empty lines till begin of text
  783.     WHILE C> = -1 { Select(L.+1,C>) ; Set(#1,#1-1) };
  784.     Select(L.,C>);
  785.     Select(L[,C[ | L:,C<); Clear; Drop;
  786. * WHILE comment:
  787.     WHILE L. < #1
  788.     {
  789. * IF line is too long insert after last whole word an EOL (wrap
  790. * around mode), update #1
  791.         IF C$ > 68
  792.         {
  793.           Select(L.,68); Select(L.,C<);
  794.           Insert("\n"); Set(#1,#1+1);
  795.         }
  796. * ELSE current line is too short, hence remove EOL, update #1, and 
  797. * remove all blanks except for one till begin of next word (fill mode)
  798. * unless it is the last line
  799.         ELSE
  800.         {
  801.           IF L. < #1-1
  802.           {
  803.             Select(L.,C$ | L.+1,0); Clear; Set(#1,#1-1);
  804.             Select(L.,C<); Select(L.,C>); Insert(" ");
  805.             Push;
  806.             Select(L.,C>); Select(L[,C[ | L.,C<); Clear; Drop;
  807.           } ELSE Set(#1,#1-1);
  808.         };
  809.     };
  810. * Find "*)" which is on the current line (was filled in) and
  811. * insert an EOL before it, shift it to the left by 2 columns
  812.     Select(L.,0); FIND("*)"); Select(L.,C.);
  813.     Insert("\n");
  814.     Select(L.,C.-2 | L.,C.);  Clear;
  815. * Add an EOL after comment (has been removed during fill in) and
  816. * restore selection
  817.     Select(L.,C$); Insert("\N");
  818.     Select(L[,C[ | L.,0)!;
  819.     Drop;
  820. };
  821.  
  822.  
  823. * 29
  824. * rearrange text by wrapping the end of 
  825. * too long lines to the next line or filling lines too short lines
  826. * Option ^ W (works if text not commented (s.a. Macro 22)
  827. * left margin of text is given by first word begin in selection
  828. "Wrap text             Opt A" 300 {
  829. * save current selection and assign last line of selection to #1
  830.     Push; Set(#1,L]);
  831. * set cursor to begin of selection
  832.     Select(L[,C[);
  833. * WHILE text:
  834.     WHILE L. < #1
  835.     {
  836. * IF line is too long insert after last whole word an EOL (wrap
  837. * around mode), update #1
  838.         IF C$ > 68
  839.         {
  840.           Select(L.,68); Select(L.,C<);
  841.           Insert("\n"); Set(#1,#1+1);
  842.         }
  843. * ELSE current line is too short, hence remove EOL, update #1, and 
  844. * remove all blanks except for one till begin of next word (fill mode)
  845. * unless it is the last line
  846.         ELSE
  847.         {
  848.           IF L. < #1-1
  849.           {
  850.             Select(L.,C$ | L.+1,0); Clear; Set(#1,#1-1);
  851.             Select(L.,C<); Select(L.,C>); Insert(" ");
  852.             Push;
  853.             Select(L.,C>); Select(L[,C[ | L.,C<); Clear; Drop;
  854.           } ELSE Set(#1,#1-1);
  855.         };
  856.     };
  857. * Add an EOL after text (has been removed during fill in) and
  858. * restore selection
  859.     Select(L.,C$); Insert("\N");
  860.     Select(L[,C[ | L.,0)!;
  861.     Drop;
  862. };
  863.  
  864.  
  865. * --------------------------------------------------------------------------------
  866. * 30
  867. * insert a line in the menu (line separator)
  868. "-" {};
  869.  
  870. *-*************-*
  871. *-* Movements *-*
  872. *-*************-*
  873.  
  874.  
  875. * 31
  876. * Bring last window to front
  877. "Flip windows/H"  {
  878.     Set(#0,0);  WHILE Window(#0)  Set(#0,#0+1);  Window(#0-1);
  879. };
  880.  
  881.  
  882. * 32
  883. * Ask for a line number to jump to and do it
  884. "Jump to Line/J" {
  885.     Prompt("Goto Line",#6);
  886.     Select(#6-1,C. | #6-1,C.)!;
  887. };
  888.  
  889.  
  890. * 33
  891. * jumps to the next placeholder in a Modula-2 structure
  892. * Alternative keyboard entry: Option^G ~ 305
  893. *af*"Placeholder          Opt G/G" 305
  894. *jt*"Placeholder          Opt G/G" 305
  895. *or*"Placeholder          Opt -" 344
  896. *tn*"Placeholder          Opt -" 344
  897. "Placeholder          Opt G/G" 305 
  898. {
  899.     Find("(*.");
  900.     IF L: = 0 AND C: = 0   Find("(*.");
  901.     Push;
  902.     Find(".*)");
  903.     Select(L[,C[ | L:,C:)!;
  904.     Drop;
  905. };
  906.  
  907.  
  908. * 34
  909. * For use together with the following macros
  910. "Save position/B" {
  911.     Push;
  912. };
  913.  
  914.  
  915. * 35
  916. * Jumps back to the last position saved with macro 2 (Option^B)
  917. * the stack can hold the last eight positions
  918. "Back to position   Opt B" 311 {
  919.     Select(L[,C[)!;
  920.     Pop;
  921. };
  922.  
  923.  
  924.  
  925. *==================================================================*
  926. * !!! From here on depending on the version macros with or without *
  927. * menu entries. NOTE: macros with menu entries will function only  *
  928. * properly if they are defined in a sequence from the beginning    *
  929. * without ANY! macro stuck in between WITHOUT menu entry !!!       *
  930. *==================================================================*
  931.  
  932. * ………
  933.  
  934.  
  935. *============================================================*
  936. * !!! Add from here on only(!) macros with NO menu entry !!! *
  937. *============================================================*
  938.  
  939.  
  940. * 36
  941. * insert implementation header info:
  942.     {
  943.       Insert("  (*\N");
  944.       Insert("        Implementation and Revisions:\N");
  945.       Insert("        ============================\N");
  946.       Insert("\N");
  947.       Insert("        Author  Date        Description\N");
  948.       Insert("        ------  ----        -----------\N");
  949.       Insert("\N");
  950.       Insert(Concat("        ",SubStr($6,0,1),SubStr($7,0,1),"      ",Date(2)));
  951.       Insert("    First implementation (MacMETH_V3.2.1)\N");
  952.       Insert("\N");
  953.       Insert("  *)\N");
  954.       Insert("\N");
  955.       Insert("\N");
  956.       Insert("  (*.imports.*)\N");
  957. };
  958.  
  959. * 37
  960. * delete to end of line   option - BS ~ 351
  961. 351 {
  962.     Select(L.,C.|L.,C$);
  963.     Clear;
  964. };
  965.  
  966.  
  967. * 38
  968. * select first placeholder
  969. * !!!! this macro is called by many other macros !!!!
  970. {
  971.     Pop;
  972.     Find("(*.");
  973.     Push;
  974.     Find(".*)");
  975.     Select(L[,C[ | L:,C:)!;
  976.     Drop;
  977. };
  978.  
  979.  
  980. * 39
  981. * select current word (like double click)
  982. *: <Enter>
  983. (1,76)
  984. {
  985.     Select(L.,C< | L.,C>)!;
  986. }.
  987.  
  988. * --------------------------------------------------------------------------------
  989. *** only a maximum of 60 macros are supported by the MComp = V1.40 ***
  990.